/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cube;

import java.io.BufferedWriter;
import java.io.BufferedReader;
import java.lang.Exception;
import java.io.File;
import java.io.FileWriter;
import java.io.FileReader;

/**
 * @author charmgil
 */

public class FileIO {
    public function writeData( file: File, text: String ) {
        var output: BufferedWriter;
        
        println( "debug: at least here" );

        try{
            //def file = new File( filename );
            output = new BufferedWriter( new FileWriter( file ) );

            output.write( text );
            output.flush();
            println( "Message: Your file has been written." );

        } catch( e: Exception ){
            e.printStackTrace();
            
        } finally{
            output.close();
        }
    }

    public function readData( file: File ){
        var input: BufferedReader;
        var content;

        try{
            //def file = new File( filename );
            input = new BufferedReader( new FileReader( file ) );

            content = [ input.readLine(), input.readLine(), input.readLine(), input.readLine() ];
            println( "Message: Your file has been read." );

        } catch( e: Exception ){
            e.printStackTrace();

        } finally{
            input.close();
        }
        
        return content;
    }

}
